// *默认导出，export default render
// *命名导出，一个文件可以导出多个
export const num = 200;
export const obj = {
    name: "yiyi",
    age: 9,
};

export const render = (element, container) => {
    // ?解构赋值
    const { type, props } = element;
    //创建元素
    const el = document.createElement(type);
    //遍历属性

    Object.keys(props).forEach((attr) => {
        if (attr == "children") {
            const child = props["children"];
            if (typeof child == "string") {
                el.innerText = child;
            } else if (child instanceof Array) {
                child.forEach((item) => {
                    if (typeof item == "string") {
                        const txt = document.createTextNode(item);
                        el.appendChild(txt);
                    } else {
                        render(item, el);
                    }
                });
            } else {
                render(child, el);
            }
        } else {
            el[attr] = props[attr];
        }
    });
    // 添加元素
    container.appendChild(el);
};
